<template>
  <van-popup
    v-model="showPicker"
    position="bottom"
  >
    <van-datetime-picker
      v-model="currentDate"
      :type="typeStr"
      title="选择年月日"
      :min-date="minDate"
      :max-date="maxDate"
      @confirm="onConfirm"
      @cancel="showPicker = false"
    />
  </van-popup>
</template>

<script>
import moment from 'moment'
export default {
  name: 'AreaSelect',
  props:{
    typeStr:{
      type:String,
      default:'date'
    }
  },
  data () {
    return {
      showPicker: false,
      minDate: new Date(1900, 0, 1),
      maxDate: new Date(2099, 11, 31),
      currentDate: new Date(),
      tit: undefined
    }
  },
  methods: {
    init (tit) {
      this.tit = tit
      this.showPicker = true
    },
    onConfirm (values) {
      let day = moment(values).format('YYYY-MM-DD')
      if(this.typeStr == 'datetime'){
        day = moment(values).format('YYYY-MM-DD HH:mm')
        // day = moment(values).unix()
      }
      this.$emit('select', day, this.tit)
      this.showPicker = false;
    },
  }
}
</script>

<style lang="less" scoped>
</style>
